package com.wuyan.locationdog.viewmodel

import androidx.lifecycle.MutableLiveData
import com.arcsoft.commonbase.base.BaseViewModel
import com.arcsoft.commonbase.bean.AlarmSave
import com.arcsoft.commonbase.bean.CardNoBean
import com.arcsoft.commonbase.bean.DeviceAlarmSetBean
import com.arcsoft.commonbase.bean.DeviceBean
import com.arcsoft.commonbase.bean.DeviceBeanContent
import com.arcsoft.commonbase.bean.DeviceCheckBean
import com.arcsoft.commonbase.bean.DeviceCountBean
import com.arcsoft.commonbase.bean.DeviceDetailBean
import com.arcsoft.commonbase.bean.DeviceFlowBean
import com.arcsoft.commonbase.bean.DeviceShareBean
import com.arcsoft.commonbase.bean.DeviceShareUserInfoBean
import com.arcsoft.commonbase.bean.DogFileBean
import com.arcsoft.commonbase.bean.DogFileBeanContent
import com.arcsoft.commonbase.bean.FenceBean
import com.arcsoft.commonbase.bean.FileUploadBean
import com.arcsoft.commonbase.bean.GroupBean
import com.arcsoft.commonbase.bean.PointBean
import com.arcsoft.commonbase.bean.ProvinceBean
import com.arcsoft.commonbase.bean.ShareUrlBean
import com.arcsoft.commonbase.bean.StatisticsCountBean
import com.arcsoft.commonbase.bean.TeamDetail
import com.arcsoft.commonbase.bean.TrackBean
import com.arcsoft.commonbase.ext.customShowLong
import com.arcsoft.commonbase.net.BaseContentBean
import com.arcsoft.commonbase.net.RetrofitManager
import com.blankj.utilcode.util.ToastUtils
import okhttp3.MultipartBody
import okhttp3.RequestBody

class DeviceViewModel : BaseViewModel() {


    val groupBean = MutableLiveData<GroupBean>()
    val anyBean = MutableLiveData<Any>()
    val deviceListBean = MutableLiveData<DeviceBean>()
    val deviceFlowBean = MutableLiveData<DeviceFlowBean>()
    val deviceBeanContent = MutableLiveData<DeviceBeanContent>()
    val deviceDetailBean = MutableLiveData<DeviceDetailBean>()

    val deviceCheckBean = MutableLiveData<DeviceCheckBean>()
    val deviceAlarmSetBean = MutableLiveData<DeviceAlarmSetBean>()
    val deviceCountBean = MutableLiveData<DeviceCountBean>()
    val provinceBean = MutableLiveData<ProvinceBean>()
    val cityBean = MutableLiveData<ProvinceBean>()
    val fenceBean = MutableLiveData<FenceBean>()
    val deviceShareBean = MutableLiveData<DeviceShareBean>()
    val trackBean = MutableLiveData<TrackBean>()
    val statisticsCountBean = MutableLiveData<StatisticsCountBean>()
    val shareUrlBean = MutableLiveData<ShareUrlBean>()
    val deviceShareUserInfoBean = MutableLiveData<DeviceShareUserInfoBean>()


    val error = MutableLiveData<Exception>()
    val deleteSuccess = MutableLiveData<Any>()
    val removeSuccess = MutableLiveData<Any>()


    val mTeamDetail = MutableLiveData<BaseContentBean<TeamDetail>>()
    val mTeamDetailList = MutableLiveData<BaseContentBean<MutableList<TeamDetail>>?>()

    val fileUploadBean = MutableLiveData<FileUploadBean>()
    val mDogFileBean = MutableLiveData<DogFileBean>()
    val mCardNoBean = MutableLiveData<CardNoBean>()
    val mDogFileBeanContent = MutableLiveData<BaseContentBean<DogFileBeanContent>>()
    val mPointBean = MutableLiveData<BaseContentBean<MutableList<PointBean>>>()

    fun fileUpload(map: HashMap<String, RequestBody>, file: MultipartBody.Part) {
        launch(block = {
            fileUploadBean.value = RetrofitManager.apiService.fileUpload(map, file).apiData()
        })
    }

    fun addDevice(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.addDevice(map).apiData()
        })
    }

    fun deleteDevice(map: MutableList<String>) {
        launch(block = {
            deleteSuccess.value = RetrofitManager.apiService.deleteDevice(map).apiData()
        })
    }

    fun updateDevice(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.updateDevice(map).apiData()
            customShowLong("修改成功")
        })
    }

    fun resetDevice(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.resetDevice(map).apiData()
            customShowLong("重置成功")
        })
    }

    fun moveTop(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.moveTop(map).apiData()
        })
    }

    fun deviceList(map: HashMap<String, Any>) {
        launch(block = {
            deviceListBean.value = RetrofitManager.apiService.deviceList(map).apiData()
        })
    }

    fun deviceListMy(map: HashMap<String, Any>) {
        launch(block = {
            deviceListBean.value = RetrofitManager.apiService.deviceListMy(map).apiData()
        })
    }

    fun mapDeviceList(map: HashMap<String, Any>) {
        launch(block = {
            deviceListBean.value = RetrofitManager.apiService.mapDeviceList(map).apiData()
        }, error = {
            error.value = it
        })
    }

    fun mapDeviceCount(map: HashMap<String, Any>) {
        launch(block = {
            deviceCountBean.value = RetrofitManager.apiService.mapDeviceCount(map).apiData()
        })
    }

    fun mapDeviceLocation(map: HashMap<String, Any>) {
        launch(block = {
            deviceDetailBean.value = RetrofitManager.apiService.mapDeviceLocation(map).apiData()
        })
    }
    fun deviceDetail(map: HashMap<String, Any>) {
        launch(block = {
            deviceBeanContent.value = RetrofitManager.apiService.deviceDetail(map).apiData()?.content
        })
    }
    fun teamDeviceList(map: HashMap<String, Any>) {
        launch(block = {
            deviceListBean.value = RetrofitManager.apiService.teamDeviceList(map).apiData()
        })
    }

    fun deviceCheck(map: HashMap<String, Any>) {
        launch(block = {
            deviceCheckBean.value = RetrofitManager.apiService.deviceCheck(map).apiData()
        })
    }

    fun deviceFlow(map: HashMap<String, Any>) {
        launch(block = {
            deviceFlowBean.value = RetrofitManager.apiService.deviceFlow(map).apiData()
        })
    }

    fun deviceLocationRecord(map: HashMap<String, Any>, errorCallback: (e: Exception) -> Unit) {
        launch(block = {
            val apiData = RetrofitManager.apiService.deviceLocationRecord(map).apiData()
            if (apiData?.content?.posList.isNullOrEmpty()) {
                errorCallback.invoke(java.lang.Exception(""))
            } else {
                trackBean.value = apiData!!
            }
        }, error = errorCallback)
    }

    fun deviceLocationRecordStatistics(map: HashMap<String, Any>) {
        launch(block = {
            statisticsCountBean.value = RetrofitManager.apiService.deviceLocationRecordStatistics(map).apiData()
        })
    }

    fun deviceAlarmSet(map: HashMap<String, Any>) {
        launch(block = {
            deviceAlarmSetBean.value = RetrofitManager.apiService.deviceAlarmSet(map).apiData()
        })
    }


    fun deviceAlarmSave(map: AlarmSave) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.deviceAlarmSave(map).apiData()
        })
    }


    fun addGroup(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.addGroup(map).apiData()
        })
    }

    fun getGroupList(map: HashMap<String, Any>) {
        launch(block = {
            groupBean.value = RetrofitManager.apiService.getGroupList(map).apiData()
        })
    }

    fun updateGroup(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.updateGroup(map).apiData()
        })
    }

    fun moveGroup(map: HashMap<String, Any>) {
        launch(block = {
            removeSuccess.value = RetrofitManager.apiService.moveGroup(map).apiData()
        })
    }

    fun deleteGroup(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.deleteGroup(map).apiData()
        })
    }


    fun province(map: HashMap<String, Any>) {
        launch(block = {
            provinceBean.value = RetrofitManager.apiService.province(map).apiData()
        })
    }

    fun city(map: HashMap<String, Any>) {
        launch(block = {
            cityBean.value = RetrofitManager.apiService.city(map).apiData()
        })
    }

    fun addArea(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.addArea(map).apiData()
        })
    }

    fun updateArea(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.updateArea(map).apiData()
        })
    }

    fun delArea(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.delArea(map).apiData()
        })
    }

    fun areaList(map: HashMap<String, Any>) {
        launch(block = {
            fenceBean.value = RetrofitManager.apiService.areaList(map).apiData()
        })
    }


    fun addShare(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.addShare(map).apiData()
        })
    }

    fun shareList(map: HashMap<String, Any>) {
        launch(block = {
            deviceShareBean.value = RetrofitManager.apiService.shareList(map).apiData()
        })
    }

    fun shareAcceptList(map: HashMap<String, Any>) {
        launch(block = {
            deviceShareBean.value = RetrofitManager.apiService.shareAcceptList(map).apiData()
        })
    }

    fun sharePersonList(map: HashMap<String, Any>) {
        launch(block = {
            deviceShareBean.value = RetrofitManager.apiService.sharePersonList(map).apiData()
        })
    }

    fun shareCancel(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.shareCancel(map).apiData()
        })
    }

    fun shareRecentPersonList(map: HashMap<String, Any>) {
        launch(block = {
            deviceShareBean.value = RetrofitManager.apiService.shareRecentPersonList(map).apiData()
        })
    }

    fun shareUrl(map: HashMap<String, Any>) {
        launch(block = {
            shareUrlBean.value = RetrofitManager.apiService.shareUrl(map).apiData()
        })
    }

    fun shareUserInfo(map: HashMap<String, Any>) {
        launch(block = {
            deviceShareUserInfoBean.value = RetrofitManager.apiService.shareUserInfo(map).apiData()
        })
    }


    fun getTeamDetailByCode(map: HashMap<String, Any>) {
        launch(block = {
            mTeamDetail.value = RetrofitManager.apiService.getTeamDetailByCode(map).apiData()
        })
    }

    fun getTeamDetail(map: HashMap<String, Any>) {
        launch(block = {
            mTeamDetail.value = RetrofitManager.apiService.getTeamDetail(map).apiData()
        })
    }
    fun getTeamShareMsgDetail(map: HashMap<String, Any>) {
        launch(block = {
            mTeamDetail.value = RetrofitManager.apiService.getTeamShareMsgDetail(map).apiData()
        })
    }
    fun getTeamList(map: HashMap<String, Any>) {
        launch(block = {
            mTeamDetailList.value = RetrofitManager.apiService.getTeamList(map).apiData()
        })
    }

    fun addTeam(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.addTeam(map).apiData()
        })
    }

    fun teamUpdate(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.teamUpdate(map).apiData()
        })
    }

    fun teamDeviceShare(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.teamDeviceShare(map).apiData()
        })
    }

    fun teamDeviceCancel(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.teamDeviceCancel(map).apiData()
        })
    }

    fun getTeamAddPerson(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.getTeamAddPerson(map).apiData()
        })
    }
    fun getTeamQuit(map: HashMap<String, Any>) {
        launch(block = {
            deleteSuccess.value = RetrofitManager.apiService.getTeamQuit(map).apiData()
        })
    }
    fun addDog(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.addDog(map).apiData()
        })
    }

    fun updateDog(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.updateDog(map).apiData()
        })
    }
    fun firstBindDog(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.firstBindDog(map).apiData()
        })
    }
    fun getDogDetail(map: HashMap<String, Any>) {
        launch(block = {
            mDogFileBeanContent.value = RetrofitManager.apiService.getDogDetail(map).apiData()
        })
    }

    fun getDogList(map: HashMap<String, Any>) {
        launch(block = {
            mDogFileBean.value = RetrofitManager.apiService.getDogList(map).apiData()
        })
    }
    fun getAreaDogList(map: HashMap<String, Any>) {
        launch(block = {
            mDogFileBean.value = RetrofitManager.apiService.getAreaDogList(map).apiData()
        })
    }
    fun getCardNo(map: HashMap<String, Any>) {
        launch(block = {
            mCardNoBean.value = RetrofitManager.apiService.getCardNo(map).apiData()
        })
    }

    fun dogBind(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.dogBind(map).apiData()
        })
    }

    fun dogUnBind(map: HashMap<String, Any>) {
        launch(block = {
            removeSuccess.value = RetrofitManager.apiService.dogUnBind(map).apiData()
        })
    }

    fun pointAdd(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.pointAdd(map).apiData()
        })
    }

    fun pointDelete(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.pointDelete(map).apiData()
        })
    }

    fun pointList(map: HashMap<String, Any>) {
        launch(block = {
            mPointBean.value = RetrofitManager.apiService.pointList(map).apiData()
        })
    }
}